package com.vito.dcs.sys.transportVehicle.action;

import java.util.List;
import java.util.Map;

import com.vito.base.authoriza.cache.SessionMap;
import com.vito.base.authoriza.model.UserModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vito.base.authoriza.action.BaseAction;
import com.vito.dcs.sys.transportVehicle.model.SysTransportVehicleModel;
import com.vito.dcs.sys.transportVehicle.service.SysTransportVehicleService;
import com.vito.base.model.Result;
import com.vito.base.exception.ParamErrorException;
import com.vito.base.model.ResMsg;
import com.vito.base.util.*;
import com.vito.base.util.StringUtil.TreeConvert;

/**
 * 运输车辆表请求控制器
 * @author  Feng J. E-mail: 
 * @version 0.1.1
 * @date    2019-3-28 11:41:15
 */
@Controller
@RequestMapping("/dcs/sys/transportVehicle")
public final class SysTransportVehicleAction extends BaseAction {
	
	private static final Logger log = LoggerFactory.getLogger(SysTransportVehicleAction.class);
	
	@Reference
	private SysTransportVehicleService systransportvehicleServiceImpl;
	
	/**
	 * 保存运输车辆表
	 * @author  Feng J. E-mail: 
	 * @version 创建时间：2019-3-28 11:41:15
	 * @return  code:状态码 ,msg:提示信息
	 * @param   systransportvehicle 需要保存的运输车辆表对象
	*			3434
	 *		 	<li>PlateNumber:车牌号 不能为null 或空字符串</li>
	 *		 	<li>VehicleIdentity:车辆标识 不能为null 或空字符串</li>
	 *		 	<li>DeviceNo:设备编号 不能为null 或空字符串</li>
	 *		 	<li>Load:载重（吨） 不能为null 或空字符串</li>
	 */
	@RequestMapping("saveSysTransportVehicle")
	@ResponseBody
	public Result saveSysTransportVehicle(@RequestBody SysTransportVehicleModel systransportvehicle){
		Result res = new Result();
        UserModel user =SessionMap.getObj();
        if(null==user){
            res.setCode(Result.CODE_LOGIN_REQUIRE);
            res.setMsg(ResMsg.MSG_LOGIN_NEED);
            return res;
        }
		try{
			Validata.isNullOrEmpty(systransportvehicle, "运输车辆表不能为空");
			Validata.isNullOrEmpty(systransportvehicle.getPlateNumber(), "车牌号不能为空");
			Validata.isNullOrEmpty(systransportvehicle.getVehicleIdentity(), "车辆标识不能为空");
			Validata.isNullOrEmpty(systransportvehicle.getDeviceNo(), "设备编号不能为空");
			Validata.isNullOrEmpty(systransportvehicle.getVehicleLoad(), "载重（吨）不能为空");
			systransportvehicleServiceImpl.saveSysTransportVehicle(systransportvehicle);
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.SAVESUC);
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("保存失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 分页查询运输车辆表
	 * @author  Feng J. E-mail: 
	 * @version 创建时间：2019-3-28 11:41:15
	 * @return  {code:0,data:{total:20,rows:[{}...]}}
	 * @param   systransportvehicle 依靠运输车辆表对象分页查询
	 *          <li>pageNo default 1</li>
	 *          <li>pageSize default 15</li>
	 */
	@RequestMapping("querySysTransportVehicleByPage")
	@ResponseBody
	public Result querySysTransportVehicleByPage(SysTransportVehicleModel systransportvehicle){
		Result res = new Result();
        UserModel user =SessionMap.getObj();
        if(null==user){
            res.setCode(Result.CODE_LOGIN_REQUIRE);
            res.setMsg(ResMsg.MSG_LOGIN_NEED);
            return res;
        }
		try{
			Validata.isNullOrEmpty(systransportvehicle, "运输车辆表不能为空");
			if(systransportvehicle.getCreateTime()!=null&&!"".equals(systransportvehicle.getCreateTime())){
				try{
					Validata.is(systransportvehicle.getCreateTime().toString(),"添加时间格式不合法","DATE");
					systransportvehicle.setCreateTime(systransportvehicle.getCreateTime());
				}catch(ParamErrorException e){
				}
				Validata.is(systransportvehicle.getCreateTime().toString(),"添加时间格式不合法","DATE_TIME");
			}
			if(systransportvehicle.getUpdateTime()!=null&&!"".equals(systransportvehicle.getUpdateTime())){
				try{
					Validata.is(systransportvehicle.getUpdateTime().toString(),"最近更新时间格式不合法","DATE");
					systransportvehicle.setUpdateTime(systransportvehicle.getUpdateTime());
				}catch(ParamErrorException e){
				}
				Validata.is(systransportvehicle.getUpdateTime().toString(),"最近更新时间格式不合法","DATE_TIME");
			}
			res.setData(systransportvehicleServiceImpl.querySysTransportVehicleByPage(systransportvehicle));
			res.setCode(Result.CODE_OK);
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("查询失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 查询一条运输车辆表
	 * @author  Feng J. E-mail: 
	 * @version 创建时间：2019-3-28 11:41:15
	 * @return  {code:0,data:{...}}
	 * @param   systransportvehicle 依靠运输车辆表对象查询
	 */
	@RequestMapping("querySysTransportVehicle")
	@ResponseBody
	public Result querySysTransportVehicle(SysTransportVehicleModel systransportvehicle){
		Result res = new Result();
        UserModel user =SessionMap.getObj();
        if(null==user){
            res.setCode(Result.CODE_LOGIN_REQUIRE);
            res.setMsg(ResMsg.MSG_LOGIN_NEED);
            return res;
        }
		try{
			if(systransportvehicle.getCreateTime()!=null&&!"".equals(systransportvehicle.getCreateTime())){
				try{
					Validata.is(systransportvehicle.getCreateTime().toString(),"添加时间格式不合法","DATE");
					systransportvehicle.setCreateTime(systransportvehicle.getCreateTime());
				}catch(ParamErrorException e){
				}
				Validata.is(systransportvehicle.getCreateTime().toString(),"添加时间格式不合法","DATE_TIME");
			}
			if(systransportvehicle.getUpdateTime()!=null&&!"".equals(systransportvehicle.getUpdateTime())){
				try{
					Validata.is(systransportvehicle.getUpdateTime().toString(),"最近更新时间格式不合法","DATE");
					systransportvehicle.setUpdateTime(systransportvehicle.getUpdateTime());
				}catch(ParamErrorException e){
				}
				Validata.is(systransportvehicle.getUpdateTime().toString(),"最近更新时间格式不合法","DATE_TIME");
			}
			res.setData(systransportvehicleServiceImpl.querySysTransportVehicle(systransportvehicle));
			res.setCode(Result.CODE_OK);
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("查询失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
		
	/**
	 * 更新运输车辆表对象
	 * @author  Feng J. E-mail: 
	 * @version 创建时间：2019-3-28 11:41:15
	 * @return  {code:0,data:10}
	 * @param   systransportvehicle 依靠运输车辆表对象的id变更传入的其他属性值
	 *		 	<li>Id:主键ID 不能为null 或空字符串</li>
	 *		 	<li>PlateNumber:车牌号 不能为null 或空字符串</li>
	 *		 	<li>VehicleIdentity:车辆标识 不能为null 或空字符串</li>
	 *		 	<li>DeviceNo:设备编号 不能为null 或空字符串</li>
	 *		 	<li>Load:载重（吨） 不能为null 或空字符串</li>
	 */
	@RequestMapping("updateSysTransportVehicle")
	@ResponseBody
	public Result updateSysTransportVehicle(@RequestBody SysTransportVehicleModel systransportvehicle){
		Result res = new Result();
        UserModel user = SessionMap.getObj();
        if(null==user){
            res.setCode(Result.CODE_LOGIN_REQUIRE);
            res.setMsg(ResMsg.MSG_LOGIN_NEED);
            return res;
        }
		try{
		
		Validata.isNullOrEmpty(systransportvehicle.getId(),"主键ID不能为空");
		Validata.isNullOrEmpty(systransportvehicle.getPlateNumber(), "车牌号不能为空");
		Validata.isNullOrEmpty(systransportvehicle.getVehicleIdentity(), "车辆标识不能为空");
		Validata.isNullOrEmpty(systransportvehicle.getDeviceNo(), "设备编号不能为空");
		Validata.isNullOrEmpty(systransportvehicle.getVehicleLoad(), "载重（吨）不能为空");
            systransportvehicle.setUpdateUser(user.getUserId());
			res.setData(systransportvehicleServiceImpl.updateSysTransportVehicle(systransportvehicle));
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.UPDSUC);
			
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("更新失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 删除运输车辆表对象
	 * @author  Feng J. E-mail: 
	 * @version 创建时间：2019-3-28 11:41:15
	 * @return  {code:0,data:10}
	 * @param   systransportvehicle 删除运输车辆表对象的 checkeds 标识的id对应的数据
	 */
	@RequestMapping("deleteSysTransportVehicle")
	@ResponseBody
	public Result deleteSysTransportVehicle(SysTransportVehicleModel systransportvehicle){
		Result res = new Result();
        UserModel user =SessionMap.getObj();
        if(null==user){
            res.setCode(Result.CODE_LOGIN_REQUIRE);
            res.setMsg(ResMsg.MSG_LOGIN_NEED);
            return res;
        }
		try{
			Validata.isNullOrEmpty(systransportvehicle.getCheckeds(), "所选项不能为空");
			
			res.setData(systransportvehicleServiceImpl.deleteSysTransportVehicle(systransportvehicle));
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.DELCOM);
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("删除失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
}



